<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>展开运算符</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <script type="text/javascript">
        // 展开运算符...
        let arr1 = [1, 3, 5, 7, 9]
        let arr2 = [2, 4, 6, 8, 10]
        console.log(...arr1) //展开一个数组
        console.log(...arr2) //连接一个数组
        let arr3 = [...arr1, ...arr2]
        //在函数中使用
        function sum(...number) {
            return number.reduce((pre, curr) => {
                return pre + curr
            }, 0)
        }
        // console.log(sum(...arr3))
        let person = {
            name: 'tom',
            age: 18,
        }
        /******
         * Uncaught TypeError: Spread syntax requires ...iterable[Symbol.iterator] to be a function
    at 展开运算符.html:29:17
         * ***********/
        //console.log(...person) //此种写法是错误的 展开运算符不能展开对象
        //构造字面量对象时使用扩展语法
        let person1 = {
            ...person
        }
        console.log(person1)
        //合并的操作
        let person3 = {
            ...person,
            name: "老李",
            address: "地球"
        }
        console.log("@@@", person3)
    </script>
</body>

</html>